﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace AimGameLibrary.GameObject
{
    public class Drawsprite : Image2D
    {

        public Drawsprite(SpriteBatch inputspritebatch, Camera inputcamera)
            :base(inputspritebatch,inputcamera)
        {

        }

        public override void LoadData(Identification getdata, int IndexData, NodeData node)
        {
            String Temp = node.Data;
            Listnameparent.Add(Script.GetName(Temp, 9, 0));
            Listnameparent.Add(Script.GetName(Temp, 9, 1));
            Listnameparent.Add(Script.GetName(Temp, 9, 2));
            Listnameparent.Add(Script.GetName(Temp, 9, 3));
            Listnameparent.Add(Script.GetName(Temp, 9, 4));
            Listnameparent.Add(Script.GetName(Temp, 9, 5));
            Listnameparent.Add(Script.GetName(Temp, 9, 6));
            Listnameparent.Add(Script.GetName(Temp, 9, 7));
            Listnameparent.Add(Script.GetName(Temp, 9, 8));
        }

        public override void SetupParent(Dictionary<string, BaseGameObject> dictionary)
        {
            base.SetupParent(dictionary);
            if(Listparent[0].GetType() == typeof(GameTexture2D))
            {
                GameTexture2D gametexture2d = (GameTexture2D)Listparent[0];
                this.MyTexture2D = gametexture2d.Texture2D;
            }
            
        }

        public void InputtexturE(GameTexture2D gametexture2d)
        {
            this.MyTexture2D = gametexture2d.Texture2D;
        }

        public override void Draw()
        {
            int Count = 0;

            if (Listparent[0].GetType() == typeof(GameVideoPlayer))
            {
                GameVideoPlayer videoplayer = (GameVideoPlayer)Listparent[0];
                this.MyTexture2D = videoplayer.VideoTexturE;
            }

            #region Position
            Count = GetIndex(2);
            if (Listparent.Count >= Count && Count != 0)
            {
                if (Listparent[Count - 1].GetType() == typeof(GameVector2))
                {
                    GameVector2 tempvector2 = (GameVector2)Listparent[Count - 1];
                    this.MyViewData.Position = tempvector2.Myvector2;
                }
                else if (Listparent[Count - 1].GetType() == typeof(GameBody))
                {
                    GameBody tempbody = (GameBody)Listparent[Count - 1];
                    this.MyViewData.Position = new Vector2(tempbody.MybodY.X, tempbody.MybodY.Y);
                }
            }
            #endregion

            #region Souce
            Count = GetIndex(3);
            if (Listparent.Count >= Count && Count != 0)
            {
                if (Listparent[Count - 1].GetType() == typeof(GameRectangle))
                {
                    GameRectangle temprectangle = (GameRectangle)Listparent[Count - 1];
                    this.MyViewData.Source = temprectangle.MyrectanglE;
                }
                else if (Listparent[Count - 1].GetType() == typeof(GameAnimation2D))
                {
                    GameAnimation2D tempanimation = (GameAnimation2D)Listparent[Count - 1];
                    this.MyViewData.Source = tempanimation.MyrectanglE;
                }
            }
            #endregion

            #region Color
            Count = GetIndex(4);
            if (Listparent.Count >= Count && Count != 0)
            {
                if (Listparent[Count - 1].GetType() == typeof(GameColor))
                {
                    GameColor temprectangle = (GameColor)Listparent[Count - 1];
                    this.MyViewData.Colors = temprectangle.MycoloR;
                }
            }
            #endregion

            #region Rotation
            Count = GetIndex(5);
            if (Listparent.Count >= Count && Count != 0)
            {
                if (Listparent[Count - 1].GetType() == typeof(GameFloat))
                {
                    GameFloat tempfloat = (GameFloat)Listparent[Count - 1];
                    this.MyViewData.Rotation = tempfloat.MyfloaT;
                }
            }
            #endregion

            #region Origin
            Count = GetIndex(6);
            if (Listparent.Count >= Count && Count != 0)
                if (Listparent[Count - 1].GetType() == typeof(GameVector2))
            {
                GameVector2 tempvector2 = (GameVector2)Listparent[Count - 1];
                this.MyViewData.Origin = tempvector2.Myvector2;
            }
            #endregion

            #region Scale
            Count = GetIndex(7);
            if (Listparent.Count >= Count && Count != 0)
                if (Listparent[Count - 1].GetType() == typeof(GameVector2))
            {
                GameVector2 tempScale = (GameVector2)Listparent[Count - 1];
                this.MyViewData.Scale = tempScale.Myvector2;
            }
            #endregion

            #region SpriteEffect
            Count = GetIndex(8);
            if (Listparent.Count >= Count && Count != 0)
            {
                if (Listparent[Count - 1].GetType() == typeof(GameSpriteEffects))
                {
                    GameSpriteEffects temprectangle = (GameSpriteEffects)Listparent[Count - 1];
                    this.MyViewData.Spriteeffects = temprectangle.MyspriteeffectS;
                }
            }
            #endregion

            #region Depth
            Count = GetIndex(9);
            if (Listparent.Count >= Count && Count != 0)
                if (Listparent[Count - 1].GetType() == typeof(GameFloat))
            {
                GameFloat tempFloat = (GameFloat)Listparent[Count - 1];
                this.MyViewData.Depth = tempFloat.MyfloaT;
                if (this.MyViewData.Depth < 0)
                    this.MyViewData.Depth = 0;
                if (this.MyViewData.Depth > 1)
                    this.MyViewData.Depth = 1;
            }
            #endregion

            base.Draw();
        }

    }
}
